package leetcode.hard;

import java.util.Arrays;
import java.util.stream.IntStream;

/**
 * ClassName: $135_disCandy
 * Description:
 * date: 2021-09-30 10:27
 *
 * @author liyifan
 */
public class $135_disCandy {
    public int candy(int[] ratings) {
        int[] res = new int[ratings.length];
        for(int i = 0;i < res.length;i++) {
            res[i] = 1;
        }
        for (int i = 1;i < ratings.length;i++) {
            if (ratings[i] > ratings[i - 1])
                res[i] = res[i - 1] + 1;
        }
        for (int i = ratings.length - 1;i > 0;i--) {
            if (ratings[i] < ratings[i - 1]) {
                res[i - 1] = Math.max(res[i] + 1, res[i - 1]);
            }
        }
        return IntStream.of(res).sum();
    }
}
